<template>
  <div class="dashboard">
    <el-row :gutter="10">
      <el-col :span="6">
        <card title="分类商品数量(饼图)">
          <pie-echart :pieData="categoryGoodsCount"></pie-echart>
        </card>
      </el-col>
      <el-col :span="12">
        <card title="不同城市商品销量">
          <map-echart></map-echart>
        </card>
      </el-col>
      <el-col :span="6">
        <card title="分类商品数量(玫瑰图)">
          <rose-echart :roseData="categoryGoodsCount"></rose-echart>
        </card>
      </el-col>
    </el-row>
    <el-row :gutter="10" class="content-row">
      <el-col :span="12">
        <card title="分类商品的销量">
          <line-echart v-bind="categoryGoodsSale"></line-echart>
        </card>
      </el-col>
      <el-col :span="12">
        <card title="分类商品的收藏">
          <bar-echart v-bind="categoryGoodsFavor"></bar-echart>
        </card>
      </el-col>
    </el-row>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent } from 'vue'
import { useStore } from '@/store'
import Card from '@/base-ui/card/index'
import { pieEchart, roseEchart, lineEchart, barEchart, mapEchart } from '@/components/page-echarts/index'
export default defineComponent({
  name: 'dashboard',
  components: { Card, pieEchart, roseEchart, lineEchart, barEchart, mapEchart },
  setup() {
    const store = useStore()
    store.dispatch('dashboard/getDashboardDataAction')
    // 饼图 玫瑰图数据
    const categoryGoodsCount = computed(() => {
      return store.state.dashboard.categoryGoodsCount.map((item: any) => {
        return { name: item.name, value: item.goodsCount }
      })
    })
    // 折线图数据
    const categoryGoodsSale = computed(() => {
      const xLabels: string[] = []
      const values: any[] = []
      const categoryGoodsSaleData = store.state.dashboard.categoryGoodsSale
      for (const item of categoryGoodsSaleData) {
        xLabels.push(item.name)
        values.push(item.goodsCount)
      }
      return { xLabels, values }
    })

    const categoryGoodsFavor = computed(() => {
      const xLabels: string[] = []
      const values: any[] = []
      const categoryGoodsFavorData = store.state.dashboard.categoryGoodsFavor
      for (const item of categoryGoodsFavorData) {
        xLabels.push(item.name)
        values.push(item.goodsFavor)
      }
      return { xLabels, values }
    })
    return {
      categoryGoodsCount,
      categoryGoodsSale,
      categoryGoodsFavor
    }
  }
})
</script>

<style scoped lang="less">
.content-row {
  margin-top: 20px;
}
</style>
